

#### OLS for Issues and Divisions
#clear memory 
rm( list=ls() )

#### Regressions (OLS)

library("openxlsx")
library("rio")
library("jtools")

getwd ()
setwd("/Users/yongjaekim/Documents/Papers/CCP Control2")

Mydata1<-read.xlsx("GiniIssues6.xlsx")
View(Mydata1)

## Descriptive Statistics
summary(Mydata1)

#### jtools ## https://cran.r-project.org/web/packages/jtools/vignettes/summ.html
#### change IV name: https://jtools.jacob-long.com/reference/export_summs.html#arguments

## bivariate linear regression models: VI
reg1 <- lm(valenceissues ~ giniindex, data = Mydata1)
reg2 <- lm(valenceissues ~ ICKanbur, data = Mydata1)
reg3 <- lm(valenceissues ~ URKanbur, data = Mydata1)
reg4 <- lm(valenceissues ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")
library("ggplot2")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
            stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
           scale = TRUE, 
           coefs = c("Gini" = "giniindex",
                     "Inland / Coastal" = "ICKanbur", 
                     "Urban / Rural 1" = "URKanbur", 
                     "Urban / Rural 2" = "URMolero"
                     ))
p1 

Mylabel <-labs(title = "(a) Valence Issues")
p1 + Mylabel


plot_summs(reg1, reg2, reg3, reg4, 
           scale = TRUE, plot.distributions = TRUE)

## Scatterplot
effect_plot(reg1, pred = giniindex, interval = TRUE, plot.points = TRUE)
print(reg1)
summ(reg1) 
summ (reg1, robust = "HC1") # Report robust standard errors
summ(reg1, scale = TRUE) # Standardized/scaled coefficients


## bivariate linear regression models: Positional Issues
reg1 <- lm(positionalissues ~ giniindex, data = Mydata1)
reg2 <- lm(positionalissues ~ ICKanbur, data = Mydata1)
reg3 <- lm(positionalissues ~ URKanbur, data = Mydata1)
reg4 <- lm(positionalissues ~ URMolero, data = Mydata1)

library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "(b) Positional Issues")
p1 + Mylabel


plot_summs(reg1, reg2, reg3, reg4, 
           scale = TRUE, plot.distributions = TRUE)

## Scatterplot
effect_plot(reg1, pred = giniindex, interval = TRUE, plot.points = TRUE)
print(reg1)
summ(reg1) 
summ (reg1, robust = "HC1") # Report robust standard errors
summ(reg1, scale = TRUE) # Standardized/scaled coefficients


## bivariate linear regression models: Party Issues
reg1 <- lm(partyissues ~ giniindex, data = Mydata1)
reg2 <- lm(partyissues ~ ICKanbur, data = Mydata1)
reg3 <- lm(partyissues ~ URKanbur, data = Mydata1)
reg4 <- lm(partyissues ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "(c) Party Issues")
p1 + Mylabel

plot_summs(reg1, reg2, reg3, reg4, 
           scale = TRUE, plot.distributions = TRUE)

## Scatterplot
effect_plot(reg1, pred = giniindex, interval = TRUE, plot.points = TRUE)
print(reg1)
summ(reg1) 
summ (reg1, robust = "HC1") # Report robust standard errors
summ(reg1, scale = TRUE) # Standardized/scaled coefficients

 
## bivariate linear regression models: commandeconomy

reg1 <- lm(commandeconomy ~ giniindex, data = Mydata1)
reg2 <- lm(commandeconomy ~ ICKanbur, data = Mydata1)
reg3 <- lm(commandeconomy ~ URKanbur, data = Mydata1)
reg4 <- lm(commandeconomy ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Command Economy 
          (Position)")
p1 + Mylabel

## bivariate linear regression models: socialistmovement

reg1 <- lm(socialistmovement ~ giniindex, data = Mydata1)
reg2 <- lm(socialistmovement ~ ICKanbur, data = Mydata1)
reg3 <- lm(socialistmovement ~ URKanbur, data = Mydata1)
reg4 <- lm(socialistmovement ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Socialist Movement 
          (Position)")
p1 + Mylabel


## bivariate linear regression models: maoism
  
  reg1 <- lm(maoism ~ giniindex, data = Mydata1)
reg2 <- lm(maoism ~ ICKanbur, data = Mydata1)
reg3 <- lm(maoism ~ URKanbur, data = Mydata1)
reg4 <- lm(maoism ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Maoism 
(Position)") 
p1 + Mylabel

## bivariate linear regression models: communism

reg1 <- lm(communism ~ giniindex, data = Mydata1)
reg2 <- lm(communism ~ ICKanbur, data = Mydata1)
reg3 <- lm(communism ~ URKanbur, data = Mydata1)
reg4 <- lm(communism ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Communism 
   (Position)")
p1 + Mylabel

## bivariate linear regression models: economicdevelopment

reg1 <- lm(economicdevelopment ~ giniindex, data = Mydata1)
reg2 <- lm(economicdevelopment ~ ICKanbur, data = Mydata1)
reg3 <- lm(economicdevelopment ~ URKanbur, data = Mydata1)
reg4 <- lm(economicdevelopment ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Economic Development 
            (Valence)")
p1 + Mylabel

## bivariate linear regression models: consistentdevelopment

reg1 <- lm(consistentdevelopment ~ giniindex, data = Mydata1)
reg2 <- lm(consistentdevelopment ~ ICKanbur, data = Mydata1)
reg3 <- lm(consistentdevelopment ~ URKanbur, data = Mydata1)
reg4 <- lm(consistentdevelopment ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Consistent Development 
            (Valence)")
p1 + Mylabel

## bivariate linear regression models: listofpartyelites

reg1 <- lm(listofpartyelites ~ giniindex, data = Mydata1)
reg2 <- lm(listofpartyelites ~ ICKanbur, data = Mydata1)
reg3 <- lm(listofpartyelites ~ URKanbur, data = Mydata1)
reg4 <- lm(listofpartyelites ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "List of Party Elites 
          (Party)")
p1 + Mylabel

## bivariate linear regression models: partyannouncement

reg1 <- lm(partyannouncement ~ giniindex, data = Mydata1)
reg2 <- lm(partyannouncement ~ ICKanbur, data = Mydata1)
reg3 <- lm(partyannouncement ~ URKanbur, data = Mydata1)
reg4 <- lm(partyannouncement ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Party Announcement 
            (Party)")
p1 + Mylabel

## bivariate linear regression models: politicaldiscipline

reg1 <- lm(politicaldiscipline ~ giniindex, data = Mydata1)
reg2 <- lm(politicaldiscipline ~ ICKanbur, data = Mydata1)
reg3 <- lm(politicaldiscipline ~ URKanbur, data = Mydata1)
reg4 <- lm(politicaldiscipline ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Political Discipline 
          (Party)")
p1 + Mylabel

## bivariate linear regression models: poleconreform

reg1 <- lm(poleconreform ~ giniindex, data = Mydata1)
reg2 <- lm(poleconreform ~ ICKanbur, data = Mydata1)
reg3 <- lm(poleconreform ~ URKanbur, data = Mydata1)
reg4 <- lm(poleconreform ~ URMolero, data = Mydata1)


library("huxtable")
library("broom.mixed")

## Table output for Word and RMarkdown Documents
export_summs(reg1, reg2, reg3, reg4,  
             stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), scale = TRUE)

### Comparing model coefficients visually
p1 <- plot_summs(reg1, reg2, reg3, reg4, legend.title = " ", 
                 scale = TRUE, 
                 coefs = c("Gini" = "giniindex",
                           "Inland / Coastal" = "ICKanbur", 
                           "Urban / Rural 1" = "URKanbur", 
                           "Urban / Rural 2" = "URMolero"
                 ))
p1

Mylabel <-labs(title = "Political & Economic Reform 
              (Party)")
p1 + Mylabel


  
  
  
  
  
  
  
